package homework_04;

import java.util.Arrays;

/**
 * 编程题1
 */
public class Test_01 {
    public static void main(String[] args) {
        char[] carr = {'n','e','u','s','o','f','t','e','d','u','c','a','t','i','o','n'};
        ArrCopy(carr);
        int[] iarr = {1,6,2,3,9,4,5,7,8};
        ArrSort(iarr);
        int[][] arrf = new int[2][3];
        arrf[0] = new int[]{2,3,4};
        arrf[1] = new int[]{4,6,8};
        int[][] arrs = new int[3][4];
        arrs[0] = new int[]{1,5,2,8};
        arrs[1] = new int[]{5,9,10,-3};
        arrs[2] = new int[]{2,7,-5,-18};
        int[][] arrmp = arrNew(arrf,arrs);
        for(int i=0;i<arrmp.length;i++){
            System.out.println(Arrays.toString(arrmp[i]));
        }
    }

    public static void ArrOut(){
        int[] arr = {20,30,40,50,60};
        System.out.println(Arrays.toString(arr));
    }

    public static void ArrCopy(char[] carr){
        char[] ccarr = Arrays.copyOfRange(carr,0,carr.length);
        System.out.println(Arrays.toString(ccarr));
    }

    public static void ArrSort(int[] arr){
        for(int i=1;i<arr.length;i++){
            for(int j=0;j<arr.length-1;j++){
                if(arr[j]>arr[j+1]){
                    int m = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = m;
                }
            }
        }
        System.out.println(Arrays.toString(arr));
    }

    public static int[][] arrNew(int[][] arr1,int[][] arr2){
        int[][] arrT = new int[2][4];
        for(int i=0;i<arrT.length;i++){
            int[] arrTmp = new int[4];
            for(int j=0;j<arr2[0].length;j++){
                for(int k=0;k<arr2.length;k++){
                    arrTmp[j] += arr1[i][k] * arr2[k][j];
                }
            }
            arrT[i] = arrTmp;
        }
        return arrT;
    }
}
